home *** CD-ROM | disk | FTP | other *** search
- /* 4567890123456789012345678901234567890123456789012345678901234567 */
- /*
- * File: Document.c
- * Author: Mark H. Linton
- * Creation Date: 4/24/95
- * Modification Date:
- * Description: A sample procedural shell for a typical
- * Macintosh document.
- */
- #include <Icons.h>
- #include <Errors.h>
-
- #include "Document.h"
-
- #include "Toolbox.h"
-
- #include "DSDocumentList.h"
-
- static OSErr DrawDocumentData(short aType, Ptr aValue, long aRefCon);
- static OSErr WriteDocumentData(short aType, Ptr aValue, long aRefCon);
- static OSErr RemoveDocumentData(short aType, Ptr aValue, long aRefCon);
-
- #if STRICT_WINDOWS
- void DoContentClick(WindowRef aWindow, EventRecord *anEvent) {
- #else
- void DoContentClick(WindowPtr aWindow, EventRecord *anEvent) {
- #endif
- GrafPtr theCurrentPort;
- OSErr theError;
- Rect theRect;
- Point *thePoint;
-
- GetPort(&theCurrentPort);
- #if STRICT_WINDOWS
- SetPortWindowPort(aWindow);
- #else
- SetPort(aWindow);
- #endif
-
- GlobalToLocal(&anEvent->where);
- thePoint = (Point *)NewPtrClear(sizeof(Point));
- if (thePoint != nil) {
- thePoint->h = anEvent->where.h;
- thePoint->v = anEvent->where.v;
- theError = DSAddDocumentData(aWindow, kIconFamily,
- (Ptr)thePoint);
- } else {
- theError = MemError();
- }
- if (theError == noErr) {
- theError = DSWindowDirty(aWindow);
- }
- if (theError == noErr) {
- theRect.left = anEvent->where.h - 16;
- theRect.right = theRect.left + 32;
- theRect.top = anEvent->where.v - 16;
- theRect.bottom = theRect.top + 32;
- InvalRect(&theRect);
- }
-
- SetPort(theCurrentPort);
-
- if (theError != noErr) {
- ReportError(theError);
- }
- }
-
- #if STRICT_WINDOWS
- void DoDrawDocument(WindowRef aWindow) {
- #else
- void DoDrawDocument(WindowPtr aWindow) {
- #endif
- GrafPtr theCurrentPort;
- OSErr theError;
- RgnHandle theCurrentClip;
- Rect theClipRect;
-
- GetPort(&theCurrentPort);
- #if STRICT_WINDOWS
- SetPortWindowPort(aWindow);
- #else
- SetPort(aWindow);
- #endif
-
- theCurrentClip = NewRgn();
- GetClip(theCurrentClip);
- #if STRICT_WINDOWS
- theClipRect = GetWindowPort(aWindow)->portRect;
- #else
- theClipRect = aWindow->portRect;
- #endif
- theClipRect.right -= 15;
- theClipRect.bottom -= 15;
- ClipRect(&theClipRect);
-
- theError = DSForEachDocumentDataDo(aWindow, DrawDocumentData, 0L);
-
- SetClip(theCurrentClip);
- DisposeRgn(theCurrentClip);
-
- SetPort(theCurrentPort);
-
- if (theError != noErr) {
- ReportError(theError);
- }
- }
-
- OSErr DrawDocumentData(short aType, Ptr aValue, long aRefCon) {
- OSErr theError;
- Rect theRect;
- Point thePoint;
-
- switch (aType) {
- case kIconFamily:
- thePoint = *(Point *)aValue;
- theRect.left = thePoint.h - 16;
- theRect.right = theRect.left + 32;
- theRect.top = thePoint.v - 16;
- theRect.bottom = theRect.top + 32;
- theError = PlotIconID(&theRect, atNone, ttNone, 131);
- break;
- default:
- theError = paramErr;
- }
- return theError;
- }
-
- #if STRICT_WINDOWS
- OSErr DoWriteDocument(WindowRef aWindow, short aDFRefNum) {
- #else
- OSErr DoWriteDocument(WindowPtr aWindow, short aDFRefNum) {
- #endif
- OSErr theError;
- short theDataCount;
- long theSize;
-
- theError = DSCountDocumentData(aWindow, &theDataCount);
- theError = SetFPos(aDFRefNum, fsFromStart, 0L);
- theSize = sizeof(short);
- theError = FSWrite(aDFRefNum, &theSize, &theDataCount);
- theError = DSForEachDocumentDataDo(aWindow, WriteDocumentData,
- (long)aDFRefNum);
-
- return theError;
- }
-
- OSErr WriteDocumentData(short aType, Ptr aValue, long aRefCon) {
- OSErr theError;
- Point thePoint;
- long theSize;
-
- switch (aType) {
- case kIconFamily:
- thePoint = *(Point *)aValue;
- theSize = sizeof(Point);
- theError = FSWrite((short)aRefCon, &theSize, &thePoint);
- break;
- default:
- theError = paramErr;
- }
- return theError;
- }
-
- #if STRICT_WINDOWS
- OSErr DoReadDocument(WindowRef aWindow) {
- #else
- OSErr DoReadDocument(WindowPtr aWindow) {
- #endif
- OSErr theError;
- short theDataCount, theItem;
- short theFRefNum;
- long theSize;
- Point *thePoint;
-
- theError = DSGetWindowDFRefNum(aWindow, &theFRefNum);
- theError = SetFPos(theFRefNum, fsFromStart, 0L);
- theSize = sizeof(short);
- theError = FSRead(theFRefNum, &theSize, &theDataCount);
- theSize = sizeof(Point);
- for (theItem = 0; theItem < theDataCount; theItem++) {
- thePoint = (Point *)NewPtrClear(sizeof(Point));
- if (thePoint != nil) {
- theError = FSRead(theFRefNum, &theSize, thePoint);
- theError = DSAddDocumentData(aWindow, kIconFamily,
- (Ptr)thePoint);
- }
- }
-
- return theError;
- }
-
- #if STRICT_WINDOWS
- OSErr DoRemoveDocumentData(WindowRef aWindow) {
- #else
- OSErr DoRemoveDocumentData(WindowPtr aWindow) {
- #endif
- OSErr theError;
-
- theError = DSForEachDocumentDataDo(aWindow, RemoveDocumentData,
- 0L);
- return theError;
- }
-
- OSErr RemoveDocumentData(short aType, Ptr aValue, long aRefCon) {
- OSErr theError;
-
- switch (aType) {
- case kIconFamily:
- DisposePtr(aValue);
- theError = MemError();
- break;
- default:
- theError = paramErr;
- }
- return theError;
- }
-
-